<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h2>{{ message }}</h2>
    <p>"{{ date }}"</p>
  </div>
</template>

<script>
import { ref, onMounted, onUnmounted } from 'vue'
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  setup() {
    const message = ref('Vue 3.0的欢迎信息')
    const date = ref(new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' }))

    const updateIsoDate = () => {
      date.value = new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' })
    }

    onMounted(() => {
      const intervalId = setInterval(updateIsoDate, 1000)
      onUnmounted(() => {
        clearInterval(intervalId)
      })
    })
    return {
      message,
      date
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
